<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>侦听器</title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<input type="text" placeholder="firstName" v-model="firstName"> <br>
			<input type="text" placeholder="lastName" v-model="lastName"> <br>
			<h4>fullName:{{fullName}}</h4>
		</div>
		<script>
			//1. 实例化一个Vue的实例
			let vm = new Vue({
				el: '#app',
				data: {
                    firstName:'',
					lastName:'',
					fullName:'' 
				},
				watch:{
					//侦听firstName值的改变:firstName必须对应到data属性中的firstName
					//当firstName的值改变,那么触发侦听器,调用函数,val表示新的数据
					firstName:function(val){
					  this.fullName=val+" "+this.lastName;	
					},
					lastName(val){
					  this.fullName=this.firstName+" "+val; 
					}
				}
			});
		</script>
	</body>
</html>
